package cn.wang.mapper;

import cn.wang.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface IBrandMapper extends Mapper<Brand>, IdListMapper<Brand,Long> {

    @Insert("insert tb_category_brand(brand_id,category_id) values(#{bid},#{cid})")
    int insertBrandCategory(@Param("bid")Long bid,@Param("cid") Long cid);


    @Delete("delete from tb_category_brand where brand_id = #{bid}")
    int deleteBrandCategoryByBid(Long bid);

    @Select("select b.* from tb_brand b inner join tb_category_brand cb on b.id = cb.brand_id where cb.category_id = #{cid}")
    List<Brand> selectBrandsByCid(Long cid);
}
